/* eslint-disable max-classes-per-file */
/*
 * @Description:
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-08-16 17:36:20
 * @LastEditors: zss 'zss872406501@163.com'
 * @LastEditTime: 2024-04-08 09:24:07
 */
import { N_oSetupPanel } from '../../types';
import { T_compPanelConf } from '../compConfPanel';
import { T_toolbarLib } from '../compToolbar';
import { T_compBase } from './compBase';

// type I_tableStyle = N_oSetupPanel.N_comps.I_tableStyle;
type I_compToolbar = N_oSetupPanel.N_comps.I_compToolbar;
type I_messageConf = N_oSetupPanel.N_comps.I_messageConf;

export class T_multiFormConf {
  name: string;

  comment: string;

  isCreated: boolean;

  status: string;

  toolbar: I_compToolbar;

  tableDataSetting: {
    editable: boolean;
    autoload: boolean;
  };

  multiTables: Array<{ value: object }>;

  formStyle: {
    pixelWidth: number;
    percentageWidth: number;
    columnNum: number;
  };

  messageConfig: I_messageConf;
}
export class T_multiForm extends T_compBase {
  public conf: T_multiFormConf = new T_multiFormConf();

  private TtoolbarLib: T_toolbarLib = new T_toolbarLib();

  private TcompPanelConf: T_compPanelConf = new T_compPanelConf();

  constructor() {
    super();
    this.conf = {
      name: '',
      comment: '',
      isCreated: false,
      status: '',
      toolbar: null, // 工具栏
      tableDataSetting: {
        editable: true,
        autoload: true
      },
      multiTables: [],
      formStyle: {
        pixelWidth: 0,
        percentageWidth: 0,
        columnNum: 0
      },
      messageConfig: {
        custDefListener: {
          search: [],
          coordination: null
        },
        emitActions: {
          search: [],
          refresh: []
        },
        eventGroup: null
      }
    };
    this.conf.toolbar = this.TtoolbarLib.getCompToolBarSet(
      N_oSetupPanel.N_comps.COMP_NAME.MULTI_FORM
    );
  }

  public getConf(): T_multiFormConf {
    return this.conf;
  }

  public getComponentId(): N_oSetupPanel.N_comps.COMP_MODULE_ID {
    return N_oSetupPanel.N_comps.COMP_MODULE_ID.MULTI_FORM;
  }

  public GetCompPanelConf(): N_oSetupPanel.N_comps.I_setupPanel {
    return this.TcompPanelConf.getCompPanelSet(
      N_oSetupPanel.N_comps.COMP_NAME.MULTI_FORM
    );
  }

  public getPermissionList(
    config: T_multiFormConf
  ): Array<N_oSetupPanel.I_permission> {
    return [
      {
        type: 'button',
        area: 'toolbar',
        data: this.getToolbarKey(config)
      }
    ];
  }

  private getToolbarKey(config: T_multiFormConf): Array<string> {
    return Object.keys(this.conf.toolbar);
  }
}
